package dashboard;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Mail {
	// ...
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    
    
    private static Mail instance;
    public Mail()
    {
    	
    }  
    
    public static Mail getInstance()
    {
    	if(instance == null)
    		instance = new Mail();
    	return instance;
    }
    public void sendRegisterMsg(String to, String name)
    {
    	String msgBody = "Welcome to our App, ";
    	try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("cedric.judicq@gmail.com", "Dashboard.com Admin"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(to, name));
            msg.setSubject("Your DashBoard account has been created");
            msg.setText(msgBody + name);
            Transport.send(msg);

        } catch (AddressException e1) {
            // ...
        } catch (MessagingException e) {
            // ...
        } catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
    }
    public void sendForgotPasswordMsg(String to,String name, String password)
    {
    	String msgBody = "Dear " + name + " , how could you forget your password? Here is your password: " + password;
    	try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("cedric.judicq@gmail.com", "no-reply"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(to, name));
            msg.setSubject("Your DashBoard account has been created");
            msg.setText(msgBody + name);
            Transport.send(msg);

        } catch (AddressException e1) {
            // ...
        } catch (MessagingException e) {
            // ...
        } catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
    }
}
